<script setup>
	import {
		onLaunch,
		onShow,
		onHide
	} from "@dcloudio/uni-app";

	import {
		onMounted,
		watch
	} from "vue";

	// 国际化
	import {
		t,
		Language
	} from "@/i18n/index.js";

	// 1. 先定义所有 TabBar 页面的路径（与 pages.json 一致）
	const tabBarPagePaths = [
		"/pages/table/index/index",
		"/pages/table/mine/mine"
	];
	const tabBarList = [{
			index: 0,
			key: "LanguageObj.tabBarList.index"
		},
		{
			index: 1,
			key: "LanguageObj.tabBarList.mine"
		}
	];

	// 2. 判断当前页面是否为 TabBar 页面
	const isTabBarPage = () => {
		const pages = getCurrentPages();
		const currentPage = pages[pages.length - 1] ? pages[pages.length - 1] : "/pages/table/index/index";
		const currentPath = `/${currentPage.route}`; // 拼接成完整路径（如 "/pages/table/index/index"）
		return tabBarPagePaths.includes(currentPath);
	};

	// 3. 优化后的设置 TabBar 文本函数
	const setTabBarText = () => {
		// 仅在 TabBar 页面调用 setTabBarItem
		if (isTabBarPage()) {
			tabBarList.forEach((item, index) => {
				uni.setTabBarItem({
					index: item.index,
					text: t(item.key)
				});
			});
		}
	};

	// 4. 初始化 + 监听语言变化
	onMounted(() => {
		setTimeout(setTabBarText, 100);
	});
	watch(Language, setTabBarText, {
		immediate: true
	});

	onLaunch(() => {
		console.log("App Launch");
	});
	onShow(() => {
		console.log("App Show");
	});
	onHide(() => {
		console.log("App Hide");
	});
</script>

<style lang="scss">
	// uview-next组件库
	@import "uview-next/index.scss";
</style>
<style>
	/* 字体包 */
	@import "@/assets/fonts/iconfont.css";
	/*每个页面公共css */
</style>